********************************************************************************
* Replication file for Cui (2020 JEEM)
* "Climate change and adaptation in agriculture: Evidence from US cropping patterns"
*
* Step 2.1: Baseline regression and robustness checks
********************************************************************************

* set path
	
	global family "..."
	global data  ".../dta"
	
* load data

	use $data/dataForReg, clear
	
	xtset fips year

	keep if year>=1980
	

* CLU (1) baseline plus (15, 20, 25 year MA version) 
	forvalues t = 15(5)30 {
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma`t'_tAvg i.P_group#c.ma`t'_prec ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
		if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_ma`t'_t1	
	}
	
	* report results	
	esttab clu_ma*_t1, b(3) se(4) keep(*ma*) 	
		
	
* CLU (2) main in census years
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if inlist(year,1982,1987,1992,1997,2002,2007,2012) & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t2

* CLU (3) controlling for lagged prices
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec lprice*lag ///
		i.stateansi#c.t i.stateansi#c.t2 ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t3		
	
* CLU (4) state-by-year FE
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec ///
		i.stateansi#i.t i.year ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t4
	
* CLU (5) main + lag weather 
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec ///
		i.T_group#c.(lag_tAvg) i.P_group#c.(lag_prec) ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t5	
	
* report estimates: Models 1-5	
	
	esttab clu_ma30_t1 clu_t2 clu_t3 clu_t4 clu_t5, b(3) se(4) keep(*ma30* lprice* *tAvg *prec) 
	
	
* CLU (6) main + log(pop)
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec l_pop ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t6		
	
* CLU (7) main + log(areaInsured)
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec l_areaInsured* ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t7			
	
* CLU (8) main + log(crp_area+1) restricted to post-1986
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec l_crp_area ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if year>1985 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t8			
	
* CLU (9) main + log(cashrent_dfl)
	gen l_cashrent_dfl = log(cashrent_dfl)
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec l_cashrent_dfl ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t9			
	
* CLU (10) main + log(acres_cropland)
		
	qui xtreg l_pl_acre_corn_soy i.T_group#c.ma30_tAvg i.P_group#c.ma30_prec l_acres_cropland ///
		i.stateansi#c.t i.stateansi#c.t2 i.year ///
			if year>1980 & irr_ratio <0.1 & pl_yrs_cs>=20, fe vce(cluster stateansi)
	estimates store clu_t10
	
* report estimates: Models 6-10	
	
	esttab clu_t6 clu_t7 clu_t8 clu_t9 clu_t10, b(3) se(4) keep(*ma30* l_*) 	
